<template>
  <div class="app-container">

    <!-- <el-row class="row-mbinfo">
      <el-col :span="1.5">
        <el-button type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport">导出</el-button>
      </el-col>

    </el-row> -->
    <div class="divTable">
      <el-table border
        v-loading="loading"
        :data="dataList">
        <el-table-column label="门店名称"
          align="center"
          prop="storeName"
          min-width="160px"
          show-overflow-tooltip />

        <el-table-column label="金币"
          align="center"
          prop="balance"
          min-width="100px" />
        <el-table-column label="银币"
          align="center"
          prop="redBag"
          min-width="100px" />

        <el-table-column label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="140">
          <template slot-scope="scope">
            <el-button size="mini"
              type="text"
              icon="el-icon-zoom-in"
              @click="handleShowDetail(scope.row)">查看明细</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- <pagination v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList" /> -->
    </div>

    <el-dialog title="门店负债明细"
      :visible.sync="open"
      width="800px"
      append-to-body>
      <el-row class="mb10">
        <el-col>
          <el-button type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport">导出</el-button>
        </el-col>
      </el-row>
      <el-table border
        v-loading="detailLoading"
        :data="detailList">
        <el-table-column label="storeName"
          align="center"
          prop="storeName"
          min-width="200px"
          show-overflow-tooltip />
        <el-table-column label="客户名称"
          align="center"
          prop="customerName"
          min-width="160px"
          show-overflow-tooltip />
        <el-table-column label="电话"
          align="center"
          prop="phone"
          min-width="160px" />

        <el-table-column label="金币"
          align="center"
          prop="balance"
          min-width="100px" />
        <el-table-column label="银币"
          align="center"
          prop="redBag"
          min-width="100px" />
      </el-table>
      <pagination v-show="detailTotal > 0"
        :total="detailTotal"
        :page.sync="detailQarams.pageNum"
        :limit.sync="detailQarams.pageSize"
        @pagination="toGetDetailList" />
      <div slot="footer"
        class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  financeStoreDebts,
  financeStoreDebtsDetail
} from "@/api/finance/finance"

export default {
  name: "Order",
  data () {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 查询参数
      // queryParams: {
      //   pageNum: 1,
      //   pageSize: 10,
      //   payMethod: '',
      //   payTimeArray: [],
      //   storeIds: [],
      //   orderStatus: '',
      //   payStatus: ''
      // },
      dataList: [],
      open: false,

      detailList: [],
      detailLoading: false,
      detailTotal: 0,
      detailQarams: {
        pageNum: 1,
        pageSize: 10,
      },
      storeId: '',
      storeName: ''
    };
  },
  created () {
    this.getList();
  },
  methods: {
    handleShowDetail (row) {
      this.storeId = row.storeUid
      this.storeName = row.storeName
      this.detailQarams.pageNum = 1
      this.open = true
      this.toGetDetailList()
    },
    toGetDetailList () {
      this.detailLoading = true
      financeStoreDebtsDetail({
        storeId: this.storeId,
        query: this.detailQarams
      }).then((response) => {
        this.detailList = response.rows;
        this.detailTotal = response.total;
        this.detailLoading = false;
      });
    },
    cancel () {
      this.open = false
    },
    getList () {
      this.loading = true;
      financeStoreDebts().then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },


    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 导出按钮操作 */
    handleExport () {
      let times = new Date().getTime()

      this.download(
        `prod-api/finance/storeFundDetailExport/${this.storeId}`,
        {
          // ...this.queryParams,
        },
        `${this.storeName}-${times}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss" scoped>
</style>
